<template>
<div id="Account">
	<div class="container">
		<p>
			{{ $lang('ACCOUNT') }}
			<el-breadcrumb separator-class="el-icon-arrow-right">
			  <el-breadcrumb-item :to="{ path: '/' }">{{ $lang('HOME') }}</el-breadcrumb-item>
              <el-breadcrumb-item :to="{ path: '/blocks' }" v-if="mode == 'sender'">{{ $lang('BLOCK_TAB') }}</el-breadcrumb-item>
              <el-breadcrumb-item :to="{ path: '/Transaction' }" v-else>{{ $lang('TRANSACTION') }}</el-breadcrumb-item>
			  <el-breadcrumb-item>{{ $lang('ACCOUNT') }}</el-breadcrumb-item>
			</el-breadcrumb>
		</p>
		<ul class="clearfix">
			<li>
				<el-input id="copyInp" placeholder="" v-model="address" disabled>
			    <template slot="prepend">{{ $lang('ADDRESS') }}</template>
			    <el-button @click="copyText" slot="append" icon="el-icon-tickets"></el-button>
			  </el-input>
			</li>
			<li>
				<el-input placeholder="" v-model="ether_value" disabled>
			    <template slot="prepend">{{ $lang('ETHER_VALUE') }}</template>
			  </el-input>
			</li>
			<li>
				<el-input placeholder="" v-model="mined" disabled>
			    <template slot="prepend">{{ $lang('MINED') }}</template>
			  </el-input>
			</li>
			<li>
				<el-input placeholder="" v-model="transactions" disabled>
			    <template slot="prepend">{{ $lang('TRANSACTIONS') }}</template>
			  </el-input>
			</li>
		</ul>
		<textarea ref="copy"  style="opacity: 0;" ></textarea>
		<div class="table_tab">
			<router-link :to="'/account/'+ mode + '/' + paramsId + '/accountTableF'" replace>{{ $lang('ERC_TOKEN_SHOURU') }}</router-link>
			<router-link :to="'/account/'+ mode + '/' +  paramsId +'/accountTableS'" replace>{{ $lang('ERC_TOKEN_TXNS') }}</router-link>
			<router-link :to="'/account/'+ mode + '/' + paramsId + '/accountTableT'" replace>{{ $lang('MINED_BlOCKS') }}</router-link>
		</div>
		<router-view></router-view>
	</div>
	
</div>
</template>

<script>
import axios from 'axios';
import url from '@/api/url.js';
export default {
	data(){
		return {
            address:'',
            ether_value: '',
            mined: '',
            transactions: '',
			paramsId:0,
			mode: '',
		}
	},
	created(){
		this.paramsId = this.$route.params.id;
        this.mode = this.$route.params.mode
        this.address = this.$route.params.id
        this.getAccountByAddress()
		//如果进来的是发送者  就跳转到
		if(this.mode === "sender"){
			this.$router.push(`/account/${this.mode}/${this.paramsId}/accountTableS`);
		}
	},
	methods:{
		copyText(){ // 复制文本
			var e = this.$refs.copy;
			e.value = this.address;//获取textarea的id
			e.select(); //选择textarea的文本内容
			document.execCommand("Copy"); //执行浏览器复制
			this.$Message(this.$lang('COPY_SUCCESS'));
        },
        getAccountByAddress(){
            let that = this
            const loading = this.$loading({
                text: that.$lang('loading'),
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });
            axios.get(url.urlblockH + '/block/getAccountByAddress', {
                params: {
                    address: that.$route.params.id
                }
            })
            .then(function (res) {
                // that.blockList = res.data.data
                loading.close()
                that.address = that.$route.params.id
                that.transactions = res.data.data.sumTransaction
                that.ether_value = res.data.data.assets 
                that.mined = res.data.data.sumMined 
            })
            .catch(function (error) {
                loading.close()
                console.log(error);
            })
        }
    }
}
</script>

<style scoped lang="scss">
@import '~assets/scss/account.scss';
</style>